{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024年12月1日是这一年的第336天\n"
     ]
    }
   ],
   "source": [
    "year = int(input(\"请输入年份: \"))\n",
    "month = int(input(\"请输入月份: \"))\n",
    "day = int(input(\"请输入日期: \"))\n",
    "\n",
    "months_days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "if (year % 4 == 0 and year % 100!= 0) or year % 400 == 0:\n",
    "    months_days[2] = 29\n",
    "sum_days = 0\n",
    "for i in range(1, month):\n",
    "    sum_days += months_days[i]\n",
    "sum_days += day\n",
    "print(f\"{year}年{month}月{day}日是这一年的第{sum_days}天\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "3\n",
      "5\n",
      "7\n",
      "11\n",
      "13\n",
      "17\n",
      "19\n",
      "23\n",
      "29\n",
      "31\n",
      "37\n",
      "41\n",
      "43\n",
      "47\n",
      "53\n",
      "59\n",
      "61\n",
      "67\n",
      "71\n",
      "73\n",
      "79\n",
      "83\n",
      "89\n",
      "97\n",
      "101\n",
      "103\n",
      "107\n",
      "109\n",
      "113\n",
      "127\n",
      "131\n",
      "137\n",
      "139\n",
      "149\n",
      "151\n",
      "157\n",
      "163\n",
      "167\n",
      "173\n",
      "179\n",
      "181\n",
      "191\n",
      "193\n",
      "197\n",
      "199\n",
      "211\n",
      "223\n",
      "227\n",
      "229\n",
      "233\n",
      "239\n",
      "241\n",
      "251\n",
      "257\n",
      "263\n",
      "269\n",
      "271\n",
      "277\n",
      "281\n",
      "283\n",
      "293\n",
      "307\n",
      "311\n",
      "313\n",
      "317\n",
      "331\n",
      "337\n",
      "347\n",
      "349\n",
      "353\n",
      "359\n",
      "367\n",
      "373\n",
      "379\n",
      "383\n",
      "389\n",
      "397\n",
      "401\n",
      "409\n",
      "419\n",
      "421\n",
      "431\n",
      "433\n",
      "439\n",
      "443\n",
      "449\n",
      "457\n",
      "461\n",
      "463\n",
      "467\n",
      "479\n",
      "487\n",
      "491\n",
      "499\n",
      "503\n",
      "509\n",
      "521\n",
      "523\n",
      "541\n",
      "547\n",
      "557\n",
      "563\n",
      "569\n",
      "571\n",
      "577\n",
      "587\n",
      "593\n",
      "599\n",
      "601\n",
      "607\n",
      "613\n",
      "617\n",
      "619\n",
      "631\n",
      "641\n",
      "643\n",
      "647\n",
      "653\n",
      "659\n",
      "661\n",
      "673\n",
      "677\n",
      "683\n",
      "691\n",
      "701\n",
      "709\n",
      "719\n",
      "727\n",
      "733\n",
      "739\n",
      "743\n",
      "751\n",
      "757\n",
      "761\n",
      "769\n",
      "773\n",
      "787\n",
      "797\n",
      "809\n",
      "811\n",
      "821\n",
      "823\n",
      "827\n",
      "829\n",
      "839\n",
      "853\n",
      "857\n",
      "859\n",
      "863\n",
      "877\n",
      "881\n",
      "883\n",
      "887\n",
      "907\n",
      "911\n",
      "919\n",
      "929\n",
      "937\n",
      "941\n",
      "947\n",
      "953\n",
      "967\n",
      "971\n",
      "977\n",
      "983\n",
      "991\n",
      "997\n",
      "1000以内素数的个数为: 168\n"
     ]
    }
   ],
   "source": [
    "count = 0\n",
    "for num in range(2, 1001):\n",
    "    is_prime = True\n",
    "    for i in range(2, int(num ** 0.5) + 1):\n",
    "        if num % i == 0:\n",
    "            is_prime = False\n",
    "            break\n",
    "    if is_prime:\n",
    "        count += 1\n",
    "        print(num)\n",
    "\n",
    "print(f\"1000以内素数的个数为: {count}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "该成绩对应的等级是: B\n"
     ]
    }
   ],
   "source": [
    "score = float(input(\"请输入成绩: \"))\n",
    "grade = \"A\" if score >= 90 else (\"B\" if score >= 60 else \"C\")\n",
    "print(f\"该成绩对应的等级是: {grade}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "英文字母个数: 4\n",
      "空格个数: 0\n",
      "数字个数: 1\n",
      "其它字符个数: 3\n"
     ]
    }
   ],
   "source": [
    "s = input(\"请输入一行字符串: \")\n",
    "letter_count = 0\n",
    "space_count = 0\n",
    "digit_count = 0\n",
    "other_count = 0\n",
    "for char in s:\n",
    "    if char.isalpha():\n",
    "        letter_count += 1\n",
    "    elif char.isspace():\n",
    "        space_count += 1\n",
    "    elif char.isdigit():\n",
    "        digit_count += 1\n",
    "    else:\n",
    "        other_count += 1\n",
    "\n",
    "print(f\"英文字母个数: {letter_count}\")\n",
    "print(f\"空格个数: {space_count}\")\n",
    "print(f\"数字个数: {digit_count}\")\n",
    "print(f\"其它字符个数: {other_count}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n",
      "28\n",
      "496\n"
     ]
    }
   ],
   "source": [
    "for num in range(1, 1001):\n",
    "    factor_sum = 0\n",
    "    for factor in range(1, num):\n",
    "        if num % factor == 0:\n",
    "            factor_sum += factor\n",
    "    if factor_sum == num:\n",
    "        print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "409113\n"
     ]
    }
   ],
   "source": [
    "n = int(input(\"请输入整数N: \"))\n",
    "sum_result = 0\n",
    "factorial = 1\n",
    "for i in range(1, n + 1):\n",
    "    factorial *= i\n",
    "    sum_result += factorial\n",
    "print(sum_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   *\n",
      "  ***\n",
      " *****\n",
      "*******\n",
      " *****\n",
      "  ***\n",
      "   *\n"
     ]
    }
   ],
   "source": [
    "n = int(input(\"请输入奇数N: \"))\n",
    "mid = n // 2\n",
    "# 打印上半部分\n",
    "for i in range(mid + 1):\n",
    "    print(' ' * (mid - i) + '*' * (2 * i + 1))\n",
    "# 打印下半部分\n",
    "for j in range(mid):\n",
    "    print(' ' * (j + 1) + '*' * (n - 2 * (j + 1)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 6, 7, 31, 42, 55, 55, 78, 88, 199]\n"
     ]
    }
   ],
   "source": [
    "nums = []\n",
    "for _ in range(10):\n",
    "    num = int(input(\"请输入一个数: \"))\n",
    "    nums.append(num)\n",
    "\n",
    "sorted_nums = sorted(nums)\n",
    "print(sorted_nums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]\n"
     ]
    }
   ],
   "source": [
    "# 假设已有一个排好序（升序）的数组\n",
    "arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]\n",
    "\n",
    "num_to_insert = int(input(\"请输入一个数: \"))\n",
    "\n",
    "# 找到合适的插入位置\n",
    "insert_index = 0\n",
    "for index in range(len(arr)):\n",
    "    if num_to_insert <= arr[index]:\n",
    "        insert_index = index\n",
    "        break\n",
    "    else:\n",
    "        insert_index = len(arr)\n",
    "\n",
    "# 插入该数\n",
    "arr.insert(insert_index, num_to_insert)\n",
    "\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "38\n"
     ]
    }
   ],
   "source": [
    "n = int(input(\"请输入总人数n: \"))\n",
    "people = list(range(1, n + 1))\n",
    "index = 0\n",
    "while len(people) > 1:\n",
    "    count = 0\n",
    "    while count < 3:\n",
    "        index %= len(people)\n",
    "        if people[index]!= 0:\n",
    "            count += 1\n",
    "            if count == 3:\n",
    "                people[index] = 0\n",
    "        index += 1\n",
    "    people = [p for p in people if p!= 0]\n",
    "print(people[0])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
